package com.zuxia.action;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.zuxia.iservices.InformationServicesI;
import com.zuxia.po.Infocenterinfo;

/**
 * 本Action完成新闻页面所有的功能
 * @author Administrator
 *
 */

public class InformationAction extends BaseAction  {
//私有化InformationServicesI接口
	private InformationServicesI informationServices;
	
	public InformationServicesI getInformationServices() {
		return informationServices;
	}

	public void setInformationServices(InformationServicesI informationServices) {
		this.informationServices = informationServices;
	}

	private  String  certerType;
	
	public String getCerterType() {
		return certerType;
	}

	public void setCerterType(String certerType) {
		this.certerType = certerType;
	}

	//添加新闻类型的方法
	public void addType(){
		
	   Boolean b=informationServices.addType(certerType);
	   try {
		getResponse().getWriter().println(b);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	}
	//查询所有新闻类型的方法
	public void  selectType(){
	   List  d=informationServices.selectType();
	   String s=JSON.toJSONString(d);
	   try {
		getResponse().getWriter().println(s);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	}
/**
 * 添加新闻所需要的属性
 */
	private String centerName;
	private int  centerType;
	private String  centerText;
	private Date centerTime;
	
	public String getCenterName() {
		return centerName;
	}

	public void setCenterName(String centerName) {
		this.centerName = centerName;
	}

	public int getCenterType() {
		return centerType;
	}

	public void setCenterType(int centerType) {
		this.centerType = centerType;
	}

	public String getCenterText() {
		return centerText;
	}

	public void setCenterText(String centerText) {
		this.centerText = centerText;
	}

	public Date getCenterTime() {
		return centerTime;
	}

	public void setCenterTime(Date centerTime) {
		this.centerTime = centerTime;
	}

	//添加新闻的方法
	 public void  addCenter(){
	 Boolean s=informationServices.addCenter(centerName, centerType, centerTime, centerText);
		 try {
			getResponse().getWriter().println(s);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	 //查询显示所有新闻分页的方法
	 /**
		 * 以下三个是分页查询新闻用到的字段属性
		 */
	private int pageNumber;
	private int limit;
	private String icititle;
	 public int getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}
	
	
	
	

	public String getIcititle() {
		return icititle;
	}

	public void setIcititle(String icititle) {
		this.icititle = icititle;
	}

	public void queryall(){
		String json = informationServices.queryall(pageNumber, limit, icititle);
		try {
			System.out.println(json);
			System.out.println("sdfdsafs");
			getResponse().getWriter().println(json);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
	}
	
	/**
	 * 需要用到的屬性
	 */
	private int cid;

	public int getCid() {
		return cid;
	}

	public void setCid(int cid) {
		this.cid = cid;
	}
	//選中刪除的方法
		public void czCut(){
		 Boolean c=informationServices.xzCut(cid);
		 if(c){
			 try {
					getResponse().getWriter().println(true);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		 }
		 
	}
	//根据Id查询数据显示
	public void show_Center(){
		Infocenterinfo info= informationServices.show_Center(cid);
		try {
		    String json=JSON.toJSONString(info);
			getResponse().getWriter().println(json);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	//新闻修改功能
		public void updateCenter(){
			
		Boolean b=informationServices.updateCenter(cid, centerName, centerType, centerTime, centerText);
	
		try {
			getResponse().getWriter().println(true);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}
		/**
		 * 根据类型id查出新闻的方法
		 */
		private int itiid;
		
		public int getItiid() {
			return itiid;
		}

		public void setItiid(int itiid) {
			this.itiid = itiid;
		}

		public void showAll(){
			String json=informationServices.showAll(itiid,pageNumber,limit);
		 try {
			getResponse().getWriter().println(json);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}
		
}
	
